﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DTO
{
    public static class GolbalSettings
    {
        static TaiKhoanDTO _currentUser;
        static string _mark = " \t\t(ccb)";

        public static TaiKhoanDTO CurrentUser
        {
            get { return GolbalSettings._currentUser; }
            set { GolbalSettings._currentUser = value; }
        }

        public static void MarkName(NguoiDTO nguoiDTO)
        {
            if (nguoiDTO.TinhTrang)
            {
                nguoiDTO.Ten = nguoiDTO.Ten + _mark;
            }
        }

        public static string RemoveMark(string name)
        {
            string result = name.Remove(name.IndexOf(_mark), _mark.Length);
            return result;
        }

        public static string Abbr(string str)
        {
            string result = "";
            str = " " + str;
            for (int i = 0; i < str.Length-1; i++)
            {
                if (Char.IsWhiteSpace(str[i]) && !Char.IsWhiteSpace(str[i + 1]))
                {
                    result += Char.ToUpper(str[i+1]);
                }
            }
            str.Trim();
            return result.Replace("đ", "D");
        }


        public static string Md5(string s)
        {
            System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();
            byte[] bs = System.Text.Encoding.UTF8.GetBytes(s);
            bs = x.ComputeHash(bs);
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            foreach (byte b in bs)
            {
                sb.Append(b.ToString("x2").ToLower());
            }
            return sb.ToString();
        }
    }
}
